package com.ruoyi.basicdata.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ruoyi.basicdata.domain.Village;
import com.ruoyi.basicdata.service.IVillageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 基础资料Controller
 * 
 * @author ruoyi
 * @date 2023-04-05
 */
@RestController
@RequestMapping("/village")
public class VillageController extends BaseController
{
    @Autowired
    private IVillageService villageService;

    /**
     * 查询全部
     */
    public List<Village> list(){
      return villageService.selectVillages();
    }

    /**
     * 查询基础资料列表
     */
    @RequiresPermissions("basicdata:village:list")
    @GetMapping("/list")
    public TableDataInfo list(Village village)
    {
        startPage();
        List<Village> list = villageService.selectVillageList(village);
        return getDataTable(list);
    }

    /**
     * 导出基础资料列表
     */
    @RequiresPermissions("basicdata:village:export")
    @Log(title = "基础资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Village village)
    {
        List<Village> list = villageService.selectVillageList(village);
        ExcelUtil<Village> util = new ExcelUtil<Village>(Village.class);
        util.exportExcel(response, list, "基础资料数据");
    }

    /**
     * 获取基础资料详细信息
     */
    @RequiresPermissions("basicdata:village:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(villageService.selectVillageById(id));
    }

    /**
     * 新增基础资料
     */
    @RequiresPermissions("basicdata:village:add")
    @Log(title = "基础资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Village village)
    {
        return toAjax(villageService.insertVillage(village));
    }

    /**
     * 修改基础资料
     */
    @RequiresPermissions("basicdata:village:edit")
    @Log(title = "基础资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Village village)
    {
        return toAjax(villageService.updateVillage(village));
    }

    /**
     * 删除基础资料
     */
    @RequiresPermissions("basicdata:village:remove")
    @Log(title = "基础资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(villageService.deleteVillageByIds(ids));
    }
}
